# Maintainer: Naveen M K <naveen521kk@gmail.com>

_realname=starship
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.16.0
pkgrel=4
pkgdesc="The cross-shell prompt for astronauts (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://starship.rs"
license=('spdx:ISC')
depends=("${MINGW_PACKAGE_PREFIX}-libgit2")
makedepends=("${MINGW_PACKAGE_PREFIX}-rust"
             "${MINGW_PACKAGE_PREFIX}-cmake")
optdepends=("${MINGW_PACKAGE_PREFIX}-ttf-font-nerd: Nerd Font Symbols preset")
options=('staticlibs' 'strip')
source=("${_realname}-${pkgver}.tar.gz::https://github.com/starship/starship/archive/refs/tags/v${pkgver}.tar.gz"
        "windows-0.39.0-gnullvm.patch"
        "sha1-asm-x86-windows.patch")
sha256sums=('133888e190ce1563927e16ee693da3026d2e668d975ac373f853e030743775c5'
	    'fa217d67779706fd504e0cdce654e9bc8b15c2f29e5e3c9d62219637c51d32a8'
            '2c76c732e3b132af905e31732a729158ea1b1f3cf1c275a882d5349157c34835')
noextract=("${_realname}-${pkgver}.tar.gz")

prepare() {
  tar -xzf "${srcdir}"/${_realname}-${pkgver}.tar.gz -C ${srcdir} || true
  cd "${srcdir}/${_realname}-${pkgver}"
  cargo vendor \
    --locked \
    --versioned-dirs

  mkdir -p .cargo
  cat >> .cargo/config.toml <<END

[source.crates-io]
replace-with = "vendored-sources"

[source.vendored-sources]
directory = "vendor"
END

  patch -Nbp1 -i "${srcdir}/windows-0.39.0-gnullvm.patch"
  patch -Nbp1 -i "${srcdir}/sha1-asm-x86-windows.patch"
}

build() {
  cp -r ${_realname}-${pkgver} build-${MSYSTEM}
  cd "${srcdir}/build-${MSYSTEM}"
  WINAPI_NO_BUNDLED_LIBRARIES=1 \
    ${MINGW_PREFIX}/bin/cargo build \
    --release \
    --frozen
}

package() {
  ${MINGW_PREFIX}/bin/cargo install \
  --frozen \
  --offline \
  --no-track \
  --path "build-${MSYSTEM}" \
  --root "${pkgdir}${MINGW_PREFIX}"

  install -Dm 644 build-${MSYSTEM}/LICENSE -t "${pkgdir}${MINGW_PREFIX}"/share/licenses/starship/
  install -dm 755 "${pkgdir}${MINGW_PREFIX}"/share/{bash-completion/completions,fish/vendor_completions.d,zsh/site-functions}/
  ./build-${MSYSTEM}/target/release/starship completions bash >"${pkgdir}${MINGW_PREFIX}"/share/bash-completion/completions/starship
  ./build-${MSYSTEM}/target/release/starship completions fish >"${pkgdir}${MINGW_PREFIX}"/share/fish/vendor_completions.d/starship.fish
  ./build-${MSYSTEM}/target/release/starship completions zsh >"${pkgdir}${MINGW_PREFIX}"/share/zsh/site-functions/_starship
}
